//
//  CPHistoryLotteryCell.m
//  CPApp
//
//  Created by yobet on 2018/3/23.
//  Copyright © 2018年 Class. All rights reserved.
//

#import "CPHistoryLotteryCell.h"
#import "CPColorMessageModel.h"

@interface CPHistoryLotteryCell()
@property (weak, nonatomic) IBOutlet UILabel *historyLottery;
@property (weak, nonatomic) IBOutlet UILabel *time;

@property(nonatomic,strong) NSMutableArray * lotteryMutableArr;
@end
@implementation CPHistoryLotteryCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(NSMutableArray *)lotteryMutableArr {
    if (!_lotteryMutableArr) {
        _lotteryMutableArr = [NSMutableArray array];
    }
    return _lotteryMutableArr;
}
-(UILabel *)configLabelWithIndex:(NSInteger)index {
    UILabel * label;
    if (index<self.lotteryMutableArr.count) {
        label = self.lotteryMutableArr[index];
    }else {
        label = [UILabel new];
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont systemFontOfSize:13];
        label.textAlignment = NSTextAlignmentCenter;
        label.tag = index;
        label.layer.masksToBounds = YES;
        label.layer.cornerRadius = 15;
        label.backgroundColor = HJColor(240, 8, 7);
        [self.lotteryMutableArr addObject:label];
        [self.labelView addSubview:label];
    }
    return label;
}
-(void)layoutSubviews {
    [super layoutSubviews];
    float W = 30;
    for (int i = 0; i<self.lotteryMutableArr.count; i++) {
        UILabel *label = [self configLabelWithIndex:i];
        label.frame = CGRectMake(i*(W + 5), 0, W, W);
    }
}

-(void)setLotteryModel:(CPColorMessageModel *)lotteryModel {
    _lotteryModel = lotteryModel;
    
    NSArray * arr = [[lotteryModel.kjnum stringByReplacingOccurrencesOfString:@"#" withString:@","] componentsSeparatedByString:@","];
    for (int i =0; i<arr.count; i++) {
        UILabel * label = [self configLabelWithIndex:i];
        label.text = arr[i];
        label.hidden = NO;
    }
    for (NSInteger j = arr.count; j<self.lotteryMutableArr.count; j++) {
        UILabel * label = [self configLabelWithIndex:j];
        label.hidden = YES;
    }
    [self setNeedsLayout];
    
    self.historyLottery.text = [NSString stringWithFormat:@"开奖 %@期",lotteryModel.kjissue];
    self.time.text = lotteryModel.kjdate;
    
}


-(void)setPubaddrModel:(CPColorMessageModel *)pubaddrModel {
    _pubaddrModel = pubaddrModel;
    self.historyLottery.text = pubaddrModel.pubaddr;
    self.contentLabel.text = pubaddrModel.title;
    self.time.text = pubaddrModel.pubdate;
}





@end
